package qlsl.androiddesign.view.subview.activityview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import qlsl.androiddesign.activity.subactivity.CarCategoryActivity;
import qlsl.androiddesign.adapter.subadapter.PublishTypeSecondAdapter;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 评估型号页<br/>
 * 需要传入的键：title<br/>
 * 传入的值类型： String<br/>
 * 传入的值含义：标题<br/>
 * 是否必传 ：是
 */
public class CarCategoryView extends FunctionView<CarCategoryActivity> {

	private ListView listView;

	public CarCategoryView(CarCategoryActivity activity) {
		super(activity);
		setContentView(R.layout.activity_publish_type_second);
	}

	protected void initView(View view) {
		setTitle(activity.getIntent().getStringExtra("title"));
		listView = findViewById(R.id.listView);
	}

	protected void initData() {
		setListViewData();
	}

	protected void initListener() {

	}

	public <T> void showData(T... t) {

	}

	public <T> void showNoData(T... t) {

	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.list_item:
			doClickListItem(view);
			break;
		}
	}

	@SuppressWarnings("unchecked")
	private void doClickListItem(View view) {
		int clickPosition = listView.getPositionForView(view);
		HashMap<String, Object> map = (HashMap<String, Object>) listView
				.getAdapter().getItem(clickPosition);
		Intent intent = new Intent();
		intent.putExtra("text", (String) map.get("text"));
		intent.putExtra("newprice", "15789");
		activity.setResult(0, intent);
		activity.finish();
	}

	private void setListViewData() {
		String[] descs_text_0 = new String[] { "35-v", "DH55V", "DH130-W",
				"DH170W-5K", "DH220LL-LL", "DH220LL-11", "DH220-LLL",
				"DH220LC-V" };

		String[] descs_text_1 = new String[] { "EX15V-3", "ZX17U-2", "ZX20U",
				"DH170W-5K", "DH220LL-LL", "DH220LL-11", "DH220-LLL",
				"DH220LC-V", "35-v", "AX30", "EX-35", "ZX350", "2X30UR",
				"ZX35U", "ZX30UR", "ZX350" };

		List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
		String[] texts = null;
		String title = activity.getIntent().getStringExtra("title");
		if (title.equals("日立")) {
			texts = descs_text_0;
		} else if (title.equals("大宇")) {
			texts = descs_text_1;
		}
		for (int index = 0; index < texts.length; index++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("text", texts[index]);
			list.add(map);
		}
		PublishTypeSecondAdapter adapter = new PublishTypeSecondAdapter(
				activity, list);
		listView.setAdapter(adapter);

	}

}
